package com.chushouya.order.service.admin.impl;

import com.general.framework.core.exception.Ex;
import com.general.framework.core.lang.Beans;
import com.chushouya.order.dao.entity.OrderEntity;
import com.chushouya.order.dao.repository.OrderLogRepository;
import com.chushouya.order.dao.repository.OrderRepository;
import com.chushouya.order.dto.admin.order.OrderLogQuery;
import com.chushouya.order.dto.admin.orderlog.OrderLogDTO;
import com.chushouya.order.service.admin.AdminOrderLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class AdminOrderLogServiceImpl implements AdminOrderLogService {

    @Resource
    private OrderLogRepository orderLogRepository;

    @Resource
    private OrderRepository orderRepository;

    @Override
    public List<OrderLogDTO> selectOrderLogList(Long orderId) {
        OrderLogQuery orderLogQuery = new OrderLogQuery();
        orderLogQuery.setOrderId(orderId);
        return Beans.copyList(orderLogRepository.selectList(orderLogQuery), OrderLogDTO.class);
    }

    @Override
    public List<OrderLogDTO> selectPartnerOrderLogList(Long orderId, Long partnerId) {
        OrderEntity orderEntity = orderRepository.selectByPrimaryKey(orderId);
        if (!Objects.equals(orderEntity.getPartnerId(), partnerId)) {
            throw Ex.business("订单不存在或无权限查看");
        }
        return this.selectOrderLogList(orderId);
    }
}
